﻿using Microsoft.EntityFrameworkCore;

namespace Core.DataAccess.Model
{
    public class BaseDbContext<T> : DbContext where T : DbContext
    {
        /// <summary>
        /// 是否是读取
        /// </summary>
        internal bool isReader { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="isReader"></param>
        public BaseDbContext(bool isReader = false)
        {
            this.isReader = isReader;
        }

        public BaseDbContext(DbContextOptions<T> options) : base(options) 
        {
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder
                    // 数据操作日志
                    //.UseLoggerFactory(EFLogger.GetLoggerFactory())
                    .UseSqlServer(ConnactionBuilder.GetConnactionValue(this.isReader, typeof(T).Name));
            }
        }
    }
}
